package org.lanqiao.netctoss.controller.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.lanqiao.netctoss.entity.Acount;
import org.lanqiao.netctoss.entity.Buss;
import org.lanqiao.netctoss.entity.Tariff;
import org.lanqiao.netctoss.service.impl.BussServiceImpl;
import org.lanqiao.netctoss.service.impl.TariffServiceImpl;

/**
 * Servlet implementation class DeleteServiceServlet
 */
public class DeleteServiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteServiceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		//response.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("GBK");
		if(request.getParameter("delete")!=null){
			int bus_no = Integer.parseInt(request.getParameter("delete"));
			int bus_state = -1;
			//boolean b = bussBuss.updBussState(new Buss(bus_no,bus_state,now));
			int b = new BussServiceImpl().updateBussState(new Buss(bus_no,bus_state));
			if(b>0){
				PrintWriter out = response.getWriter();
				out.print("<script>alert('删除成功!');window.location.href='../service/ServiceListServlet'</script>");
			}
		}
		if(request.getParameter("stop")!=null){
			int bus_no = Integer.parseInt(request.getParameter("stop"));
			int bus_state = 0;
			int b = new BussServiceImpl().updateBussState(new Buss(bus_no,bus_state));
			if(b>0){
				PrintWriter out = response.getWriter();
				out.print("<script>alert('暂停成功!');window.location.href='../service/ServiceListServlet'</script>");
			}
		}
		if(request.getParameter("start")!=null){
			int bus_no = Integer.parseInt(request.getParameter("start"));
			int bus_state = 1;
			int b = new BussServiceImpl().updateBussState(new Buss(bus_no,bus_state));
			if(b>0){
				PrintWriter out = response.getWriter();
				out.print("<script>alert('开通成功!');window.location.href='../service/ServiceListServlet'</script>");
			}
		}
		if(request.getParameter("modify")!=null){
			int bus_no = Integer.parseInt(request.getParameter("modify"));
			//List<Buss> lb = bussBuss.selBusstByno(new Buss(bus_no));
			List<Buss> lb = new BussServiceImpl().selectBusstByno(new Buss(bus_no));
			List<Tariff> lt = new TariffServiceImpl().selectTariffName();
			request.getSession().setAttribute("lta",lt);
			request.getSession().setAttribute("lb",lb);			
			if(lb!=null){
				request.getRequestDispatcher("../view/service/service_modi.jsp").forward(request, response);
			}			
		}
		if(request.getParameter("add")!=null){
			//List<Tariff> lt = new TariffBussImpl().selectTariffName();
			List<Tariff> lt = new TariffServiceImpl().selectTariffName();
			request.getSession().setAttribute("lta",lt);
			request.getRequestDispatcher("../view/service/service_add.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
